Hello and welcome back to this session about random numbers.
So creating random numbers is a very helpful to you to assimilate and analyze the real world processes
like playing the lottery.
So if you are good and Massa so has six you can simply calculate the likelihood of winning a lottery.
But if you don't have any clue about math and still has six yeah you can also assimilate this process
by generating random numbers and analyze and the results of your simulation so first of all let's impart
them the random module so it's not imparted by default.
So we need to impart it with them the keyboard impart and then with the function random that random
we can generate random floats in the interval 0 2 1.
So if you press surf tab we can never look here.
So it's in the interval a 0 2 1 until we get 0 point 5 to 3 something and the fear read around the cell
we get another random float.
Also on the Internet a 0 to 1.
So it's 0 point 8 9.
And every time we repeat this process we get another random float in the interval 0 to 1 and that's
a very helpful tool called the random seed where you can pass within the brackets a number here it's
one two three.
But it can be any number.
And when we create random numbers like here we need to set up the random seed before.
And as long as we have the same random seed we get the same random numbers.
So the random numbers are still random but we are so-called pseudo random because then they depend on
the random seed.
And this enables reproducibility so as long as you have the same seed as I have.
So here in this case one two three we should get them the same random numbers so let's run here.
The salad with the random seed one two three.
So we still use the random generator random at random so we would expect a random float between 0 and
1.
So here we have 0 point 0 5 2.
And uh if we repeat this process we should actually get the same random float
and this is the case so when the feed change here the random seed to say let's take 10.
So it can be any number here then we get a different random number hits or point five seven.
And if we repeat this process we get the same number because we have the same seed as before
and depending on the characteristics of our real world problem the different the random generating functions.
So here we learn about the random that random function that creates floats in the interval 0 2 1.
And that's also the function random dot rent in which creates random integers in an interview which
we can determine actually.
So let's press shift tap and have a look.
So here return random integer and range a to b including both and points.
So if you want to generate a random integer and Range 1 to 100 both ends including then our function
here is random dot rent and from 1 to 100.
So let's run the cell here.
Here we get 55 and you can also repeated so without random CTF we get different integers and let's assume
we have the problem of rolling the dice.
Yeah we can simulate rolling the dice by creating random integers and the Range 1 2 6 so now first throw
we get five and now a second throw one in our third throw two and so on and we can also create many
random numbers with a for loop.
So first of all we create an empty list and we set up the random C to 1 2 3 so we want to have the same
random numbers.
If we repeat the process here and then we say we want to have 10 random integers and Range 1 to 100.
So we have a for loop with are 10 iterations so ten times we create a random in the 10 range.
1 2 100 and each random integer We append to our list.
So let's see what we get.
And we can print out here.
So here we have a list with 10 random integers and range one to one hundred and that.
Also the length of added so of course we have 10 random integers and we can also simply change this.
So let's assume that we want to simulate rolling the dice 10 times then we can say OK I want to create
random in the just in range 1 to 6
and here we have the result of simulating rolling the dice 10 times.
So we have 1 3 1 4 3 1 1 4 5 5.
And as I said depending on the characteristics of our real world problem there are many more random
functions.
So if you press your shift tap.
So for example we can create like normal random numbers or normal random numbers.
So there are a lot of options here.
All right.
So let's create some number distribute the numbers.
Let's have a look at just tap so here we are creating normal distributed numbers.
With the U.S. and the mean and seek mass the standard deviation.
So let's assume we are we have a mean of 10 and a standard deviation of 5.
Then we can create a random number from the normal distribution with the mean 10 and standard deviation
5.
So in this example 0 point to 6.
All right.
So we are finished now with the random module and later we can see that also name pi.
There's a random module it's a uprights actually even more functionality and more options then than
the adding module here in the past the standard library.
So hope you enjoyed it and you we see us in the next lesson.
But.